<!-- <template>
    <view class="content">
        <view class="news-box">
            <u-tabs lineWidth="60" :activeStyle="{'fontSize':'16px','fontWeight':'600'}" :list="tabs" @click="tabsClick"></u-tabs>
            <view class="news-list" v-if="dataList.length>0">
                <view class="news-item" v-for="(item,index) in dataList" :key="index">
                    <u-row customStyle="margin-bottom: 10px">
                        <u-col span="8">
                            <view class="news-title" @click="toPage('/pages/news/detail',{id:item.id})">{{item.title}}</view>
                            <view class="news-time">发布时间：{{$u.timeFormat(item.createtime, 'yyyy年mm月dd日')}}</view>
                        </u-col>
                        <u-col span="4" style="align-items: flex-end;">
                            <image @click="toPage('/pages/news/detail',{id:item.id})" class="news-img" :src="baseUrl+item.title_image" mode="aspectFill"></image>
                        </u-col>
                        
                    </u-row>
                </view>
            </view>
            <u-empty v-else mode="data" text="暂无资讯" ></u-empty>
        </view>
    </view>
</template> -->

<template>
    <view class="content">
        <view class="news-box">
            <u-tabs lineWidth="60" :activeStyle="{'fontSize':'16px','fontWeight':'600'}" :list="tabs" @click="tabsClick"></u-tabs>
            <view class="news-list" v-if="dataList.length>0">
                <view class="news-item" v-for="(item,index) in dataList" :key="index">
                    <u-row customStyle="margin-bottom: 10px">
                        <u-col span="8">
                            <view class="news-title" @click="toPage('/pages/news/detail',{id:item.id})">{{item.title}}</view>
                            <view class="news-time">发布时间：{{$u.timeFormat(item.createtime, 'yyyy年mm月dd日')}}</view>
                        </u-col>
                        <u-col span="4" style="align-items: flex-end;">
                            <image @click="toPage('/pages/news/detail',{id:item.id})" class="news-img" :src="baseUrl+item.title_image" mode="aspectFill"></image>
                        </u-col>
                        
                    </u-row>
                </view>
            </view>
            <u-empty v-else mode="data" text="暂无资讯" ></u-empty>
        </view>
    </view>
</template>

<script>
// export default {
//         data() {
//             return {
//                 keywords:'',
//                 tabs:[
//                     {name:'全部',id:undefined},
//                     {name:'行业资讯',id:12},
//                     {name:'政策法规',id:16},
//                 ],

//                 dataList:[],
//                 page:1, // 当前页
//                 totalPage:1,
//                 // per_page:6,
//             }
//         },
//         onLoad() {
            
//         },
//         onShow() {
// 			this.keywords=this.vuex_keywords
// 			this.getData()
//             uni.startPullDownRefresh()
//         },
//         methods: {
//             tabsClick(e){
//                 this.category = e.id
// 				this.getData()
//                 uni.startPullDownRefresh()
//             },
//             getData(){
// 				this.dataList='';
//                 let params = {
// 				    page: this.page,
//                     category: this.category,
//                     keywords: this.keywords,
// 					per_page:6,
//                 }
//                 uni.$u.http.get('/news/index',{params: params}).then((res) => {
                
//                         this.page = res.data.current_page
//                         this.totalPage = res.data.last_page
//                         this.dataList = [...this.dataList,...res.data.data]
//                         uni.stopPullDownRefresh()
                    
//                 })
//             }
//         },
// 		onPullDownRefresh() {
// 		    this.page = 1
// 		    this.dataList = []
// 		    this.getData()
// 		},
// 		onReachBottom() {
// 		    if (this.page == this.totalPage) return false
// 		    this.page = ++this.page 
// 		    this.getData()
// 		},
//     }

export default {
        data() {
            return {
                keywords:'',
                tabs:[
                    {name:'全部',id:''},
                    {name:'行业资讯',id:12},
                    {name:'政策法规',id:16},
                ],
                category:'',
                dataList:[],
                page:1, // 当前页
                totalPage:1,
                per_page:8,
            }
        },
        onLoad(e) {
            
        },
        onShow() {
            uni.startPullDownRefresh()
			this.getData()
        },
        onPullDownRefresh() {
            this.page = 1
            this.dataList = []
            this.getData()
        },
        onReachBottom() {
            if (this.page == this.totalPage) return false
            this.page = this.page + 1
            this.getData()
        },
        methods: {
            tabsClick(e){
                this.category = e.id
				this.getData()
                uni.startPullDownRefresh()
            },
            getData(){
				this.dataList='';
                let params = {
                    category: this.category,
                    per_page: this.per_page,
                    page: this.page,
                }
                uni.$u.http.get('/news/index',{params: params}).then((res) => {
                    if(res.code==1){
                        this.page = res.data.current_page
                        this.totalPage = res.data.last_page
                        this.dataList = [...this.dataList,...res.data.data]
                        uni.stopPullDownRefresh()
                    }
                })
            }
        },
    }
</script>

<style lang="scss">
.content{
        padding: 10px 20px;
        .news-list{
            padding-top: 10px;
            .news-item{
                .news-img{
                    width: 80px;
                    height: 80px;
                    border-radius: 8px;
                }
                .news-title{
                    font-size: 16px;
                    color: rgba(51, 51, 51, 1);
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    max-height: 3.0em; /* 设置为行高的两倍 */
                    line-height: 1.5em; /* 这里的行高应与下面p标签中的行高一致 */
                    max-height: 3em; /* 最大高度为行高的两倍 */
                    white-space: normal;
                    font-weight: 600;
                }
                
                .news-time{
                    font-size: 12px;
                    color: rgba(153, 153, 153, 1);
                    line-height: 2;
                }
            }
        }
    }
</style>
